package com.gsit.expenditure.services;

import java.util.List;

import javafx.collections.ObservableList;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.gsit.expenditure.domain.Vehicle;
import com.gsit.expenditure.domain.Vendor;



@Repository("vendorService")
@Qualifier("vendorService")
public class VendorServices {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	@Transactional
	public List<Vendor> findAll() {
		return entityManager.createNamedQuery("Vendor.findAll", Vendor.class).getResultList();
	}
	
	@Transactional
	public <T> T find(Class<T> entityClass, Long id) {
		return entityManager.find(entityClass, id);
	}

	@Transactional
	public List<Vendor> findByName(String vendorname) {
		Query query= entityManager.createQuery("select vendor from Vendor vendor where firstName like '%"+vendorname+"%'");
		return query.getResultList();
	}
	
	
	@Transactional
	public Vendor saveOrUpdate(Vendor entity) {
		
		return entityManager.merge(entity);
	}
	
	

}
